package cn.itcast.cn.itcast.lambda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.stream.Stream;

public class TestStream {
    @Test
    public void testStream(){
        ArrayList<String> list = new ArrayList<>();
        list.add("赵丽颖,98");
        list.add("鹿晗,95");
        list.add("宋小宝,87");

         list.stream().map(n -> n.split(",")[1]).map(z -> Integer.parseInt(z)).filter(s -> s>90).forEach(System.out::println);

         list.stream().map(n -> n.split(",")[1]).map( Integer::parseInt).filter(s -> s>90).forEach(System.out::println);

    }


    @Test
    public void testStream1(){
        ArrayList<String> list = new ArrayList<>();
        list.add("赵丽颖,98");
        list.add("鹿晗,95");
        list.add("宋小宝,87");
        Stream<String> stream = list.stream();

        String[] arr = new String[]{"hello","world","good","morning"};
        Stream<String> stream1 = Stream.of(arr);

        int[] arr2 = new int[]{10,20};
        Stream<int[]> arr21 = Stream.of(arr2);

        Integer[] arr3 = new Integer[]{10,20};
        Stream<Integer> arr31 = Stream.of(arr3);



    }

    @Test
    public void testStream2(){
        ArrayList<String> list = new ArrayList<>();
        list.add("赵丽颖,98");
        list.add("鹿晗,95");
        list.add("宋小宝,87");


        Stream<String> stream1 = list.stream().map(s ->
            s.split(",")[1]);


       // stream1.forEach();


    }

    @Test
    public void testStream3(){
        ArrayList<Integer> list = new ArrayList<>();
        list.add(90);
        list.add(80);
        list.add(70);

        Stream<Integer> stream = list.stream().filter(x -> x > 80);
        //stream.forEach(System.out::println);
        stream.forEach(s -> System.out.println(s));


    }

    @Test
    public void testParaller(){
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add(i+"");
        }

        list.stream().parallel().forEach(System.out::println);
    }
















}
